package p30_异常处理;

import cn.hutool.core.map.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import p21_参数解析器.Person;
import p26_ControllerAdvice之ModelAttribute.WebConfig;

import java.util.Map;

@Controller
public class MyController {
    @ResponseBody
    public Person foo() {
        return null;
    }

    @ExceptionHandler
    @ResponseBody
    public Map<String, String> handle1(ArithmeticException e) {
        return MapUtil.of("error", e.getMessage());
    }



    @ExceptionHandler
    public ModelAndView handle2(NullPointerException e) {
        return new ModelAndView("test", MapUtil.of("error", e.getMessage()));
    }
}
